const mongoose = require('mongoose')

const Schema = mongoose.Schema

const articleSchema = new Schema({
  title: {
    type: String,
    required: true
  },
  author: {
    type: String,
    required: true
  },
  content: {
    type: String
  },
  cover: {
    type: String,
    default: 'https://www.ipicbed.com/images/2021/12/23/pic13.jpg'
  },
  tag: {
    type: Array
  },
  created_time: {
    type: Date,
    default: Date.now
  },
  last_modified_time: {
    type: Date,
    default: Date.now
  },
  commentArea: {
    type: [
      {
        "username": String,
        "role": String,
        "user_id": String,
        "comment_time": Date,
        "content": String
      }
    ],
    default: []
  },
  // 收藏和点赞文章的用户
  article_user: {
    collect: [
      {
        user_id: String,
        username: String
      }
    ],
    like: [
      {
        user_id: String,
        username: String
      }
    ],
    default:{}

  }
})

// const Article = mongoose.model('Article',articleSchema)

// Article.create({
//   title: "JavaScript基础一：基本介绍",
//   author: "feng",
//   cover: "https://www.ipicbed.com/images/2021/12/23/pic13.jpg",
//   created_time:new Date,
//   last_modified_time: new Date,
//   content: "这是第一篇文章，JavaScript基础一：基本介绍"
// }).then((res) => {
//   console.log('文章创建成功');
// }).catch((err) => {
//   console.log('文章创建失败');
// });

module.exports = mongoose.model('Article', articleSchema)